//
// Created by francklinson on 2021/7/7.
//
#include <vector>
#include <unordered_map>
#include <iostream>
#include <algorithm>

using namespace std;

class Solution {
public:
    static constexpr int MOD = 1'000'000'007;

    int countPairs(vector<int> &deliciousness) {
        int maxVal = *max_element(deliciousness.begin(), deliciousness.end());
        int maxSum = maxVal * 2;
        int pairs = 0;
        unordered_map<int, int> mp;
        int n = (int) deliciousness.size();
        for (auto &val : deliciousness) {
            for (int sum = 1; sum <= maxSum; sum <<= 1) { // 两数之和不会超过最大值的两倍
                int count = mp.count(sum - val) ? mp[sum - val] : 0;
                pairs = (pairs + count) % MOD;
            }
            ++mp[val];
        }
        return pairs;
    }
};

int main() {
    vector<int> deliciousness{1, 3, 1, 3, 1, 3, 7};
    Solution sol;
    cout << sol.countPairs(deliciousness) << endl;
    return 0;
}